package  
{
	import org.flixel.*;
	
	/**
	 * ...
	 * @author ...
	 */ 
	public class Level1State extends PlayState 
	{
		[Embed(source = "../data/levels/Level 1.oel", mimeType = "application/octet-stream")] private var _newLevel:Class;
		
		override public function create():void
		{
			var background1:FlxSprite = new FlxSprite(0, 0, ImageFiles.warehouseBackground);
			var background2:FlxSprite = new FlxSprite(FlxG.width, 0, ImageFiles.warehouseBackground);
			background1.scrollFactor.x = background2.scrollFactor.x = .5;
			
			var backcrates1:FlxSprite = new FlxSprite(0, FlxG.height, ImageFiles.warehouseBackCrates);
			backcrates1.y -= backcrates1.height;
			var backcrates2:FlxSprite = new FlxSprite(FlxG.width, FlxG.height, ImageFiles.warehouseBackCrates)
			backcrates2.y -= backcrates2.height;
			var frontcrates1:FlxSprite = new FlxSprite(0, FlxG.height, ImageFiles.warehouseFrontCrates);
			frontcrates1.y -= frontcrates1.height;
			var frontcrates2:FlxSprite = new FlxSprite(FlxG.width, FlxG.height, ImageFiles.warehouseFrontCrates);
			frontcrates2.y -= frontcrates2.height;
			
			backcrates1.scrollFactor.x = backcrates2.scrollFactor.x = .6;
			frontcrates1.scrollFactor.x = frontcrates2.scrollFactor.x = .7;
			
			var windows:FlxGroup = new FlxGroup();
			windows.scrollFactor.x = .5;
			var window:FlxSprite = new FlxSprite(242, 90, ImageFiles.warehouseWindow);
			windows.add(window, true);
			window = new FlxSprite(601, 90, ImageFiles.warehouseWindow);
			windows.add(window, true);
			window = new FlxSprite(960, 90, ImageFiles.warehouseWindow);
			windows.add(window, true);			

			add(background1);
			add(background2);
			add(backcrates1);
			add(backcrates2);
			add(frontcrates1);
			add(frontcrates2);
			add(windows);
			
			super.create();
			
			_playerStartingX = 0;
			_playerStartingY = 60;
			_levelTime = 120;
			
			var roomXML:XML = new XML(new _newLevel);
			
			tilemap.loadOgmoTileMap(roomXML, "tiles", TilesetImages.warehouse);
			lightningmap.loadOgmoTileMap(roomXML, "tiles", TilesetImages.warehouse);
			objectmap.loadOgmoObjects(roomXML, "objects", "lights", LightBulb, lightBulbs);
			objectmap.loadOgmoObjects(roomXML, "objects", "batteries", Battery, powerups);
			objectmap.loadOgmoObjects(roomXML, "objects", "clocks", Clock, powerups);
			objectmap.loadOgmoConveyorBelts(roomXML, "objects", conveyorBelts);
			lightningmap.loadOgmoConveyorBelts(roomXML, "objects", conveyorBelts);
			movermap.loadOgmoMovingObjects(roomXML, "objects", "movingPlatform", ImageFiles.elevator, moverGroup);
			
			_levelTransition.init();
			
			for (var i:int = 0; i < conveyorBelts.members.length; i++)
			{
				conveyorBelts.members[i].colHullY.y -= 2;
			}
			
			FlxG.followBounds(tilemap.left, tilemap.top, tilemap.right, tilemap.bottom);
			
			restartLevel();
			
			FlxG.playMusic(SoundFiles.warehouseMusic, 0.75);
			FlxG.music.fadeIn(1.0);
		}
		
	}

}